import { get_image } from '../utils'

const ResCountry = {
  _description: '国家和地区',
  _name: 'res.country',
  _fields: {
    name: { type: 'char', string: '名称' },
    code: { type: 'char', string: '缩写' },
    image: { type: 'binary', string: '国旗' },
    state_ids: {
      type: 'one2many',
      relation: 'res.country.state',
      string: '州/省'
    }
  },
  metadata: {
    actions: { create: false, write: false, unlink: false },
    // order: 'code',

    propForView: {
      fields: {
        name: null,
        code: null,
        image: null,
        state_ids: {
          // propForList: {
          //   // title: rec => {
          //   //   return `国家里的州-${rec.display_name}`
          //   // },
          //   // label: rec => {
          //   //   // return `${rec.display_name}`
          //   // },
          //   // value: rec => {
          //   //   // return `${rec.display_name}`
          //   // }
          // }
        }
      }
    },
    propForList: {
      title: rec => {
        return `${rec.code} ${rec.display_name}`
      },
      icon: rec => {
        return get_image('res.country', rec.id, 'image')
      },

      label: rec => {
        return ``
      },
      value: rec => {
        return ``
      }
    }
  }
}

const ResCountryState = {
  _description: '州/省',
  _name: 'res.country.state',
  _fields: {
    name: { type: 'char', string: '名称' },
    code: { type: 'char', string: '缩写' },
    city_ids: {
      type: 'one2many',
      relation: 'res.city',
      string: '市区县'
    }
  },

  metadata: {
    actions: { create: false, write: false, unlink: false },

    fieldsForBrowse: {
      name: null,
      code: null,
      city_ids: {
        name: null,
        zipcode: null
      }
    },

    propForList: {
      title: rec => {
        return `${rec.display_name}`
      },

      label: rec => {
        return `${rec.display_name}`
      },
      value: rec => {
        return ``
      }
    }
  }
}

const ResCity = {
  _description: '区县',
  _name: 'res.city',
  _fields: {
    name: { type: 'char', string: '名称' },
    zipcode: { type: 'char', string: '编码' }
  },

  metadata: {
    actions: { create: false, write: false, unlink: false },

    order: 'zipcode',

    propForList: {
      title: rec => {
        return `${rec.display_name}`
      },

      // label: rec => {
      //   return `编码: ${rec.zipcode}`
      // }
      value: rec => {
        return `编码: ${rec.zipcode}`
      }
    }
  }
}

const Models = {
  'res.country': ResCountry,
  'res.country.state': ResCountryState,
  'res.city': ResCity
}

export default Models
